package com.firefoxking.mysite.service.comment.impl;

import com.firefoxking.mysite.dao.CommentMapper;
import com.firefoxking.mysite.dao.dto.CommentCond;
import com.firefoxking.mysite.entity.Comment;
import com.firefoxking.mysite.service.comment.CommentService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CommentServiceImpl implements CommentService {

    @Autowired
    private CommentMapper commentMapper;

    @Override
    public int addComment(Comment comment) {
        return commentMapper.addComment(comment);
    }

    @Override
    public int deleteComment(int coid) {
        return commentMapper.deleteComment(coid);
    }

    @Override
    public int updateCommentStatus(int coid, String status) {
        return commentMapper.updateCommentsStatus(coid, status);
    }

    @Override
    public Comment getCommentById(int coid) {
        return commentMapper.getCommentById(coid);
    }

    @Override
    public List<Comment> getCommentsByCid(int cid) {
        return commentMapper.getCommentsByCid(cid);
    }

    @Override
    public PageInfo<Comment> getCommentsByCond(CommentCond commentCond, int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<Comment> comments = commentMapper.getCommentsByCond(commentCond);
        return new PageInfo<Comment>(comments);
    }
}
